<?php

namespace app\common\model\user;

use think\Model;


class Custom extends Model
{

    

    

    // 表名
    protected $name = 'user_custom';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_apply_text',
        'apply_time_text'
    ];
    

    
    public function getIsApplyList()
    {
        return ['0' => __('Is_apply 0'), '1' => __('Is_apply 1')];
    }


    public function getIsApplyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_apply']) ? $data['is_apply'] : '');
        $list = $this->getIsApplyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getApplyTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['apply_time']) ? $data['apply_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setApplyTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function custom()
    {
        return $this->belongsTo('app\common\model\Custom', 'custom_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'channel', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
